#include "InputSystem.h"

CInputSystem::CInputSystem(int flags): m_pKeyboard(NULL), m_pMouse(NULL), m_pJoystick(NULL)
{
  if (flags & IS_USEKEYBOARD)
  {
    m_pKeyboard = new CKeyboard;
  }
  if (flags & IS_USEMOUSE)
  {
    m_pMouse = new CMouse;
  }
  if (flags & IS_USEJOYSTICK)
  {
	/* Debemos iniciar el subsitema de SDL que se encarga de controlar el joystick */
	SDL_InitSubSystem(SDL_INIT_JOYSTICK);
    m_pJoystick = new CJoystick;
  }
}

CInputSystem::~CInputSystem()
{
  delete m_pKeyboard;
  delete m_pMouse;

  if (m_pJoystick)
  {
    delete m_pJoystick;
	SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
  }
}

bool CInputSystem::Update()
{
  SDL_PumpEvents();

  if (m_pKeyboard)
    m_pKeyboard->Update();
  if (m_pMouse)
    m_pMouse->Update();
  if (m_pJoystick)
    m_pJoystick->Update();

  return true;
}

